<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>



    <script>

       

            function fmCurtny(){
                return new Promise((resolve,reject)=>{
                    setTimeout(()=>{
                         let resData=Math.random()
                         // console.log(resData) 
                         if(resData>0.5){
                            resolve(resData)
                         }else{
                            reject(resData)
                         }
                    })
                })
            }


            function fmCouent(fm,times=0,delay=0){
                // console.log(times)
                return new Promise(async(resolve,reject)=>{
                   
                   let inner=function(){
                    console.log('请求已经发起了 剩余'+times)
                        setTimeout(async()=>{
                            try {
                                times--
                                let result=await fm()
                                resolve(result)
                            } catch (error) {
                                if(times<=0){
                                    reject(error)
                                }else{
                                    inner()
                                }
                            }
                        })
                   }
                   inner()
                })
            }


            fmCouent(fmCurtny,3,1000).then((res)=>{
                  console.log(res)
            }).catch((e)=>{
                  console.log(e)
            })



            

           
       
            

         


             







    </script>
    
</body>
</html>